﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace GSManager
{
     public class PhieuMuaHang
    {
         private int _SoPhieuMua;
         private DateTime _NgayMua;
         private string _MaKhachHang;
         private decimal _TongTien;
         private string _NguoiLapPhieu;
         public int SoPhieuMua
         {
             get { return _SoPhieuMua; }
             set { _SoPhieuMua = value; }
         }
         public DateTime NgayMua
         {
             get { return _NgayMua; }
             set { _NgayMua = value; }
         }
         public string MaKhachHang
         {
             get { return _MaKhachHang; }
             set { _MaKhachHang = value; }
         }
         public decimal TongTien
         {
             get { return _TongTien; }
             set { _TongTien = value; }
         }
         public string NguoiLapPhieu
         {
             get { return _NguoiLapPhieu; }
             set { _NguoiLapPhieu = value; }
         }
         public int DemSoPhieuMuaHang()
         {
             OleDbConnection connect = KetNoi.KetNoiDuLieu();
             string sql = "select Max(SoPhieuMua) from PHIEUMUAHANG";
             OleDbCommand cmd = new OleDbCommand(sql, connect);
             OleDbDataReader r = cmd.ExecuteReader();
             int kq = 0;
             while (r.Read())
             {
                 try
                 {
                     kq = (int)r[0];
                 }
                 catch (Exception) { }
             }
             r.Close();
             connect.Close();
             return kq;
         }
         public void ThemPhieuMuaHang()
         {
             OleDbConnection connect = KetNoi.KetNoiDuLieu();
             string sql = "Insert into PHIEUMUAHANG values(?,?,?,?,?)";
             OleDbCommand cmd = new OleDbCommand(sql, connect);
              cmd.Parameters.Add("@SoPhieuMua", OleDbType.Integer);
              cmd.Parameters.Add("@NgayMua", OleDbType.Date);
              
              cmd.Parameters.Add("@MaKhachHang", OleDbType.VarChar);
              cmd.Parameters.Add("@TongTien", OleDbType.Decimal);
              cmd.Parameters.Add("@NguoiLapPhieu", OleDbType.VarWChar);
              cmd.Parameters[0].Value = SoPhieuMua;
              cmd.Parameters[1].Value = NgayMua;
              cmd.Parameters[2].Value = MaKhachHang;
              cmd.Parameters[3].Value = TongTien;
              cmd.Parameters[4].Value = NguoiLapPhieu;
              cmd.ExecuteNonQuery();
              connect.Close();
         }

    }
}
